<%-- 
    Document   : administrar
    Created on : 30/06/2013, 05:36:25 PM
    Author     : CARLOS J. AVILA
--%>
<%@page import="java.sql.DriverManager"%>
<%@page import="javax.swing.table.DefaultTableModel"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%
//**********************CAMBIAR DE REQUEST A SESSION***************************
//primero verificar que quien ingresa a esta pagina es un usuario de tipo administrador
    Object tipoUsuario = session.getAttribute("tipoUsuario");
    
    if (tipoUsuario == null || (!tipoUsuario.equals("administrador") && !tipoUsuario.equals("superadministrador"))) {
        response.sendRedirect("index.jsp");
    } 


%>
<html lang="en">
    <head>

        <meta charset="utf-8">
        <title>EduShare - Administración</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="pagina de administracion del sitio.">
        <meta name="author" content="Muhammad Usman">
        <meta name="editor" content="Carlos J. Avila">

        <!-- The styles -->
        <link id="bs-css" href="css/bootstrap-classic.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
        <link href="css/charisma-app.css" rel="stylesheet">
        <link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        <link href='css/fullcalendar.css' rel='stylesheet'>
        <link href='css/fullcalendar.print.css' rel='stylesheet'  media='print'>
        <link href='css/chosen.css' rel='stylesheet'>
        <link href='css/uniform.default.css' rel='stylesheet'>
        <link href='css/colorbox.css' rel='stylesheet'>
        <link href='css/jquery.cleditor.css' rel='stylesheet'>
        <link href='css/jquery.noty.css' rel='stylesheet'>
        <link href='css/noty_theme_default.css' rel='stylesheet'>
        <link href='css/elfinder.min.css' rel='stylesheet'>
        <link href='css/elfinder.theme.css' rel='stylesheet'>
        <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
        <link href='css/opa-icons.css' rel='stylesheet'>
        <link href='css/uploadify.css' rel='stylesheet'>

        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- The fav icon -->
        <link rel="shortcut icon" href="img/favicon.ico">

    </head>

    <body>
        <!-- topbar starts -->
        <div class="navbar">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".top-nav.nav-collapse,.sidebar-nav.nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>
                    <a class="brand" href="index.jsp"> <img alt="Charisma Logo" src="img/logo20.png" /> <span>EduShare</span></a>


                    <!-- user dropdown starts -->
                    <div class="btn-group pull-right" >

                        <%
                            String correoUsuario = null;
                            //si hay una sesion activa
                            if (session != null && session.getAttribute("correo") != null) {

                                //tomar el valor del correo del usuario
                                correoUsuario = session.getAttribute("correo").toString();
                                //colocar el html para mostra el usuario y el dropdown
                        %>
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="icon-user"></i><span class="hidden-phone"><%= correoUsuario%></span>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="perfil.jsp">Perfil</a></li>
                            <li class="divider"></li>
                            <li><a href="index.jsp?cs=true">Logout</a></li>
                        </ul>
                        <%} //si no hay una session activa
                        else {%>
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="login.jsp">
                            <i class="icon-user"></i><span class="hidden-phone">Login/Registro</span>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                            <li><a href="login.jsp">Login</a></li>                            
                        </ul>
                        <%}%>
                    </div>

                </div>
            </div>
        </div>
        <!-- topbar ends -->
        <div class="container-fluid">
            <div class="row-fluid">

                <!-- left menu starts -->
                <div class="span2 main-menu-span">
                    <div class="well nav-collapse sidebar-nav">
                        <ul class="nav nav-tabs nav-stacked main-menu">
                            <li class="nav-header hidden-tablet">Menú</li>
                            <li><a class="ajax-link" href="index.jsp"><i class="icon-home"></i><span class="hidden-tablet">Inicio</span></a></li>						
                            <!-- href de form.html a articulo.html-->
                            <li><a class="ajax-link" href="articulo.jsp"><i class="icon-edit"></i><span class="hidden-tablet">Nuevo Artículo</span></a></li>
                            <!-- href de chart.html a reporte.html-->
                            <li><a class="ajax-link" href="reportes.jsp"><i class="icon-list-alt"></i><span class="hidden-tablet">Reportes</span></a></li>
                            <!-- href de table.html a busqueda.html-->
                            <li><a class="ajax-link" href="busqueda.jsp"><i class="icon-align-justify"></i><span class="hidden-tablet">Buscar</span></a></li>
                            <!-- (agregado) href a administrar.html-->
                            <li><a class="ajax-link" href="administrar.jsp"><i class="icon-align-justify"></i><span class="hidden-tablet">Administrar</span></a></li>

                        </ul>

                    </div><!--/.well -->
                </div><!--/span-->
                <!-- left menu ends -->

                <noscript>
                <div class="alert alert-block span10">
                    <h4 class="alert-heading">Warning!</h4>
                    <p>You need to have <a href="http://en.wikipedia.org/wiki/JavaScript" target="_blank">JavaScript</a> enabled to use this site.</p>
                </div>
                </noscript>

                <div id="content" class="span10">
                    <!-- content starts -->			

                    <div>
                        <ul class="breadcrumb">
                            <li>
                                <a href="#">Inicio</a> <span class="divider">/</span>
                            </li>
                            <li>
                                <a href="#">Administrar</a>
                            </li>
                        </ul>
                    </div>
                    <!-- EMPIEZA LA PRIMERA TABLA -->
                    <div class="row-fluid sortable">		
                        <div class="box span12">
                            <div class="box-header well" data-original-title>
                                <h2><i class="icon-user"></i>Usuarios</h2>
                                <div class="box-icon">
                                    <!--a href="#" class="btn btn-setting btn-round"><i class="icon-cog"></i></a-->
                                    <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>
                                    <!--a href="#" class="btn btn-close btn-round"><i class="icon-remove"></i></a-->
                                </div>
                            </div>
                            <div class="box-content">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>Correo Electrónico</th>
                                            <th>Nombre</th>
                                            <th>Fecha de Registro</th>
                                            <th>Tipo</th>
                                            <th>Status</th>
                                            <th>Acciones</th>
                                        </tr>
                                    </thead>   
                                    <tbody>

                                        <%
                                            String usuario = "sql312735";
                                            String pass = "sH9!yN8%";
                                            String ruta = "jdbc:mysql://sql3.freemysqlhosting.net:3306/sql312735";
                                            Connection conexion = null;
                                            Statement sentencias = null;
                                            ResultSet tabla = null;
                                            try {
                                                Class.forName("com.mysql.jdbc.Driver").newInstance();
                                                conexion = DriverManager.getConnection(ruta, usuario, pass);
                                                sentencias = conexion.createStatement();
                                            } catch (Exception e) {
                                                out.println("<script>alert('" + e.toString() + "')</script>");
                                            }


                                            try {


                                                tabla = sentencias.executeQuery("select "
                                                        + "U.id_usuario, "
                                                        + "U.email, "
                                                        + "U.tipo,"
                                                        + "U.nombre, "
                                                        + "H.fecha_hora "
                                                        + "from USUARIO U "
                                                        + "inner join "
                                                        + "HISTORIAL H "
                                                        + "on U.id_usuario=H.id_usuario "
                                                        + "where H.codigo_accion=0; ");

                                                while (tabla.next()) {
                                                    String func = "$('#historial" + tabla.getString("id_usuario") + "').modal('show');";

                                        %>
                                        <tr>
                                            <td><%= tabla.getString("id_usuario")%></td>
                                            <td><%= tabla.getString("email")%></td>
                                            <td><%= tabla.getString("nombre")%></td> 
                                            <td class="center"><%= tabla.getString("fecha_hora")%></td>
                                            <td class="center"><%= tabla.getString("tipo")%></td>
                                            <td class="center">
                                                <span class="label label-success">Activo</span>
                                            </td>
                                            <td class="center">
                                                <a class="btn btn-success" href="#" onclick="<%=func%>">
                                                    <i class="icon-zoom-in icon-white"></i>  
                                                    Ver Historial                                           
                                                </a>
                                                <!--EMPIEZA VENTANA MODAL-->
                                                <div class="modal hide fade" id="historial<%=tabla.getString("id_usuario")%>">
                                                    <div class="modal-header">
                                                        <button type="button" class="close" data-dismiss="modal">×</button>
                                                        <h3>Historial de <%=tabla.getString("email")%></h3>
                                                    </div>
                                                    <div class="modal-body">
                                                        <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                                            <thead>
                                                                <tr>
                                                                    <th>No</th>
                                                                    <th>Fecha y Hora</th>
                                                                    <th>Descripción</th>                                                                    
                                                                </tr>
                                                            </thead>   
                                                            <tbody>
                                                                <%
                                                                    ResultSet historial = conexion.createStatement().executeQuery("select "
                                                                            + "H.fecha_hora, "
                                                                            + "H.descripcion "
                                                                            + "from HISTORIAL H "
                                                                            + "where H.id_usuario=" + tabla.getString("id_usuario") + "; ");
                                                                    int historialNo = 0;
                                                                    while (historial.next()) {
                                                                %>
                                                                <tr>
                                                                    <td><%= historialNo+=1 %></td>
                                                                    <td><%=historial.getString("fecha_hora")%></td>
                                                                    <td><%=historial.getString("descripcion")%></td>                                                                    
                                                                </tr>
                                                                <% }
                                                                %>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <a href="#" class="btn" data-dismiss="modal">Cerrar</a>                                                        
                                                    </div>
                                                </div>
                                                <!--TERMINA VENTANA MODAL-->
                                                <a class="btn btn-danger" href="#">
                                                    <i class="icon-trash icon-white"></i> 
                                                    Deshabilitar
                                                </a>
                                            </td>
                                        </tr>
                                        <%}
                                            } catch (Exception e) {
                                                out.println("<script>alert('" + e.toString() + "')</script>");
                                                e.printStackTrace();
                                            }
                                        %>  
                                    </tbody>
                                </table>            
                            </div>
                        </div><!--/span-->
                    </div><!--/row-->
                    <!--TERMINA LA PRIMERA TABLA-->
                    <!--EMPIEZA LA SEGUNDA TABLA-->
                    <div class="row-fluid sortable">		
                        <div class="box span12">
                            <div class="box-header well" data-original-title>
                                <h2><i class="icon-user"></i>Denuncias</h2>
                                <div class="box-icon">
                                    <a href="#" class="btn btn-minimize btn-round"><i class="icon-chevron-up"></i></a>                                    
                                </div>
                            </div>
                            <div class="box-content">
                                <table class="table table-striped table-bordered bootstrap-datatable datatable">
                                    <thead>
                                        <tr>
                                            <th>No.</th>
                                            <th>Razón</th>
                                            <th>Usuario</th>
                                            <th>Artículo</th>
                                            <th>Fecha y Hora</th>
                                            <th>Justificación</th>
                                            <th>Acciones</th>
                                        </tr>
                                    </thead>   
                                    <tbody>
                                        <%
                                            try {
                                                tabla = sentencias.executeQuery("select "
                                                        + "U.id_usuario, "
                                                        + "U.email, "
                                                        + "A.id_articulo, "
                                                        + "A.titulo,"
                                                        + "RD.nombre, "
                                                        + "D.fecha_hora, "
                                                        + "D.justificacion "
                                                        + "from DENUNCIA D "
                                                        + "inner join "
                                                        + "USUARIO U "
                                                        + "on D.id_usuario=U.id_usuario "
                                                        + "inner join "
                                                        + "ARTICULO A "
                                                        + "on D.id_articulo=A.id_articulo "
                                                        + "inner join "
                                                        + "RAZON_DENUNCIA RD "
                                                        + "on D.id_razon_denuncia=RD.id_razon_denuncia ; ");
                                                int no = 0;
                                                while (tabla.next()) {

                                        %>
                                        <tr>
                                            <td><%= no += 1%></td>
                                            <td class="center"><%=tabla.getString("nombre")%></td>
                                            <td class="center"><%=tabla.getString("email")%></td>
                                            <td class="center"><%=tabla.getString("titulo")%></td>
                                            <td class="center"><%=tabla.getString("fecha_hora")%></td>
                                            <!--cuadro de texto para la justificacion-->                                            
                                            <td class="center">
                                                <strong>
                                                    <%=tabla.getString("justificacion")%>
                                                </strong>                                                
                                            </td>                                            
                                            <td class="center">
                                                <%String id_art = tabla.getString("id_articulo");%>
                                                <a class="btn btn-success" href="visorDeArticulo.jsp?id_articulo=<%= id_art%>">
                                                    <i class="icon-zoom-in icon-white"></i>  
                                                    Ver Artículo                                           
                                                </a>
                                                <%String id_us = tabla.getString("id_usuario");%>
                                                <a class="btn btn-danger" href="perfil.jsp?id_usuario=<%= id_us%>" >
                                                    <i class="icon-trash icon-white"></i> 
                                                    Ver Usuario
                                                </a>                                                
                                            </td>
                                        </tr> 
                                        <%}
                                            } catch (Exception e) {
                                                out.println("<script>alert('" + e.toString() + "')</script>");
                                                e.printStackTrace();
                                            }
                                        %>  
                                    </tbody>
                                </table>            
                            </div>
                        </div><!--/span-->
                    </div><!--/row-->
                    <!--TERMINA LA SEGUNDA TABLA-->
                </div><!--/row-->
                <!-- content ends -->
            </div><!--/#content.span10-->
        </div><!--/fluid-row-->

        <hr>

        <div class="modal hide fade" id="myModal">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">×</button>
                <h3>Settings</h3>
            </div>
            <div class="modal-body">
                <p>Here settings can be configured...</p>
            </div>
            <div class="modal-footer">
                <a href="#" class="btn" data-dismiss="modal">Close</a>
                <a href="#" class="btn btn-primary">Save changes</a>
            </div>
        </div>

        <footer>
            <p class="pull-left">&copy; <a href="http://usman.it" target="_blank">Muhammad Usman</a> 2012</p>
            <p class="pull-right">Powered by: <a href="http://usman.it/free-responsive-admin-template">Charisma</a></p>
        </footer>

    </div><!--/.fluid-container-->

    <!-- external javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/funcionesCarlos.js"></script>
    <!-- jQuery -->
    <script src="js/jquery-1.7.2.min.js"></script>
    <!-- jQuery UI -->
    <script src="js/jquery-ui-1.8.21.custom.min.js"></script>
    <!-- transition / effect library -->
    <script src="js/bootstrap-transition.js"></script>
    <!-- alert enhancer library -->
    <script src="js/bootstrap-alert.js"></script>
    <!-- modal / dialog library -->
    <script src="js/bootstrap-modal.js"></script>
    <!-- custom dropdown library -->
    <script src="js/bootstrap-dropdown.js"></script>
    <!-- scrolspy library -->
    <script src="js/bootstrap-scrollspy.js"></script>
    <!-- library for creating tabs -->
    <script src="js/bootstrap-tab.js"></script>
    <!-- library for advanced tooltip -->
    <script src="js/bootstrap-tooltip.js"></script>
    <!-- popover effect library -->
    <script src="js/bootstrap-popover.js"></script>
    <!-- button enhancer library -->
    <script src="js/bootstrap-button.js"></script>
    <!-- accordion library (optional, not used in demo) -->
    <script src="js/bootstrap-collapse.js"></script>
    <!-- carousel slideshow library (optional, not used in demo) -->
    <script src="js/bootstrap-carousel.js"></script>
    <!-- autocomplete library -->
    <script src="js/bootstrap-typeahead.js"></script>
    <!-- tour library -->
    <script src="js/bootstrap-tour.js"></script>
    <!-- library for cookie management -->
    <script src="js/jquery.cookie.js"></script>
    <!-- calander plugin -->
    <script src='js/fullcalendar.min.js'></script>
    <!-- data table plugin -->
    <!--script src='js/jquery.dataTables.min.js'></script-->

    <!-- chart libraries start -->
    <script src="js/excanvas.js"></script>
    <script src="js/jquery.flot.min.js"></script>
    <script src="js/jquery.flot.pie.min.js"></script>
    <script src="js/jquery.flot.stack.js"></script>
    <script src="js/jquery.flot.resize.min.js"></script>
    <!-- chart libraries end -->

    <!-- select or dropdown enhancer -->
    <script src="js/jquery.chosen.min.js"></script>
    <!-- checkbox, radio, and file input styler -->
    <script src="js/jquery.uniform.min.js"></script>
    <!-- plugin for gallery image view -->
    <script src="js/jquery.colorbox.min.js"></script>
    <!-- rich text editor library -->
    <script src="js/jquery.cleditor.min.js"></script>
    <!-- notification plugin -->
    <script src="js/jquery.noty.js"></script>
    <!-- file manager library -->
    <script src="js/jquery.elfinder.min.js"></script>
    <!-- star rating plugin -->
    <script src="js/jquery.raty.min.js"></script>
    <!-- for iOS style toggle switch -->
    <script src="js/jquery.iphone.toggle.js"></script>
    <!-- autogrowing textarea plugin -->
    <script src="js/jquery.autogrow-textarea.js"></script>
    <!-- multiple file upload plugin -->
    <script src="js/jquery.uploadify-3.1.min.js"></script>
    <!-- history.js for cross-browser state change on ajax -->
    <script src="js/jquery.history.js"></script>
    <!-- application script for Charisma demo -->
    <script src="js/charisma.js"></script>


</body>
</html>

